package com.sl.hx.shop.ui.mine.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.sl.hx.shop.R;
import com.sl.hx.shop.base.BaseActivity;
import com.sl.hx.shop.base.BasePresenter;
import com.sl.hx.shop.bean.CollectGoodsBean;
import com.sl.hx.shop.bean.MessageBean;
import com.sl.hx.shop.ui.home.activity.WebAvtivity;
import com.sl.hx.shop.ui.mine.adapter.MessageAdapter;
import com.sl.hx.shop.utils.ToastUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class MessageActivity extends BaseActivity {
    @BindView(R.id.back)
    ImageView back;
    @BindView(R.id.mRecyclerView)
    RecyclerView mRecyclerView;

    private MessageAdapter messageAdapter;
    private List<MessageBean> messageBeans;


    @Override
    protected int getLayoutId() {
        return R.layout.activity_message;
    }

    @Override
    protected BasePresenter createPresenter() {
        return null;
    }

    @Override
    protected void initView() {
        Intent intent = getIntent();
        Bundle args = intent.getBundleExtra("MESSAGBUNDLE");
        messageBeans = (ArrayList<MessageBean>) args.getSerializable("MESSAGELIST");
        initRecycle();
    }

    @Override
    protected void initData() {

    }

    private void initRecycle() {
        messageAdapter=new MessageAdapter(messageBeans);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mRecyclerView.setAdapter(messageAdapter);
        messageAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                if (messageAdapter.getItem(position).getUrl()!=null&&!TextUtils.isEmpty(messageAdapter.getItem(position).getUrl())){
                    Intent intent = new Intent(mContext, WebAvtivity.class);
                    intent.putExtra("webviewUrl",messageAdapter.getItem(position).getUrl());
                    intent.putExtra("webviewTitle",messageAdapter.getItem(position).getName());
                    startActivity(intent);
                }else {
                    ToastUtil.showShort(mContext,"暂无数据");
                }
            }
        });
    }



    @OnClick({R.id.back})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
        }
    }


}
